//
//  UIntStorageFormatter.h
//  EZFoundation
//
//  Created by ellzu gu on 2021/8/2.
//

#ifndef DataUIntFormatter_h
#define DataUIntFormatter_h

#include <stdint.h>

typedef struct _UIntStorage UIntStorage;
typedef struct _UIntStorageFormatter UIntStorageFormatter;

struct _UIntStorage {
    const void *data;
};

struct _UIntStorageFormatter {
    uint8_t swapEndian;
    
    uint8_t (*readBit)(const UIntStorageFormatter* formatter, const UIntStorage* storage, uint32_t offset, uint32_t bitOffset);
    void (*replaceBit)(const UIntStorageFormatter* formatter, const UIntStorage* storage, uint32_t offset, uint32_t bitOffset, uint8_t value);
    
    uint8_t (*readUInt8)(const UIntStorageFormatter* formatter, const UIntStorage* storage, uint32_t offset);
    void (*replaceUInt8)(const UIntStorageFormatter* formatter, const UIntStorage* storage, uint32_t offset, uint8_t value);
    
    uint16_t (*readUInt16)(const UIntStorageFormatter* formatter, const UIntStorage* storage, uint32_t offset);
    void (*replaceUInt16)(const UIntStorageFormatter* formatter, const UIntStorage* storage, uint32_t offset, uint16_t value);
    
    uint32_t (*readUInt32)(const UIntStorageFormatter* formatter, const UIntStorage* storage, uint32_t offset);
    void (*replaceUInt32)(const UIntStorageFormatter* formatter, const UIntStorage* storage, uint32_t offset, uint32_t value);
    
    uint64_t (*readUInt64)(const UIntStorageFormatter* formatter, const UIntStorage* storage, uint32_t offset);
    void (*replaceUInt64)(const UIntStorageFormatter* formatter, const UIntStorage* storage, uint32_t offset, uint64_t value);
};

UIntStorage MakeUIntStorage(const void *data);
UIntStorageFormatter MakeUIntStorageFormatter(uint8_t swapEndian);


uint16_t UIntStorageFormatter_swap16(uint16_t num, uint8_t swapEndian);
uint32_t UIntStorageFormatter_swap32(uint32_t num, uint8_t swapEndian);
uint64_t UIntStorageFormatter_swap64(uint64_t num, uint8_t swapEndian);

#endif /* DataUIntFormatter_h */
